
a = input()

a = int(a)
if a < 1 or a > 3999:
    raise ValueError("输入必须是1到3999之间的整数")
a = f"{a:04d}"

roman_str = ''

print(a[0],a[1],a[2],a[3])

symlist1=['M','C','X','I']
symlist2=[' ','D','L','V']

if int(a[0]) != 0:
    for i in range(int(a[0])):
        roman_str += 'M'

for j in range(1,4):
    if int(a[j]) != 0:
        if int(a[j]) <= 3:
            for i in range(int(a[j])):
                roman_str += symlist1[j]
        elif int(a[j]) == 4:
            roman_str += symlist1[j]
            roman_str += symlist2[j]
        elif int(a[j]) <= 8:
            roman_str += symlist2[j]
            for i in range(int(a[j])-5):
                roman_str += symlist1[j]
        elif int(a[j]) == 9:
            roman_str += symlist1[j]
            roman_str += symlist1[j-1]

print(roman_str)